package com.woniu.sharepark.leasesystem.tenant.controller;

import com.github.pagehelper.PageInfo;
import com.woniu.sharepark.common.JsonResult;
import com.woniu.sharepark.leasesystem.tenant.pojo.TenantComment;
import com.woniu.sharepark.leasesystem.tenant.service.TenantCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *@ClassName TenantCommentController
 *@Description 前端评分处理的controller
 *@Author litong
 *@Date 2019/6/5 11:56
 *@Version 1.0
 **/
@Controller
@RequestMapping("/tenantComment")
public class TenantCommentController {
   @Autowired
    private TenantCommentService tenantCommentService;


   /**
   * 根据被评人id分页查找所有评分
   * @title allTenantComments
   * @param oId
   * @return java.util.List<com.woniu.sharepark.leasesystem.tenant.pojo.TenantComment>
   * @author Administrator
   * @date 2019/6/5 14:27
   **/
   @RequestMapping("/allComments")
   @ResponseBody
   public Map allTenantComments(@RequestParam(value = "page",defaultValue = "1",required = false)Integer currentPage,
                                @RequestParam(value = "rows",defaultValue = "5",required = false)Integer pageSize,
                                Integer oId){

     List<TenantComment>list=new ArrayList<>();
     list=tenantCommentService.findAllComments(currentPage,pageSize,oId);
     PageInfo<TenantComment>pageInfo=new PageInfo<>(list);
     Map  map=new HashMap();
     map.put("rows",pageInfo.getList());
     map.put("total",pageInfo.getTotal());
     return map;
   }
   /**
   * 查找所有评分
   * @title allTenantComment
   * @param oId
   * @return com.woniu.sharepark.common.JsonResult
   * @author litong
   * @date 2019/6/21 15:51
   **/
    @RequestMapping("/allComment")
    @ResponseBody
    public JsonResult allTenantComment(Integer oId){return tenantCommentService.allComments(oId);}
   /**
   * 添加评分
   * @title addComment
   * @param tenantComment
   * @return com.woniu.sharepark.common.JsonResult
   * @author litong
   * @date 2019/6/5 14:50
   **/
   @RequestMapping("/addComment")
   @ResponseBody
   public JsonResult addComment(TenantComment tenantComment,Integer oId){
       return tenantCommentService.addComment(tenantComment,oId);
   }

   /**
   * 删除评分
   * @title deleteComment
   * @param tcId
   * @return com.woniu.sharepark.common.JsonResult
   * @author litong
   * @date 2019/6/5 15:49
   **/
   @RequestMapping("/deletComment")
   @ResponseBody
   public JsonResult deleteComment(Integer tcId){
       return tenantCommentService.deleteCommentById(tcId);
   }
}
